<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 19/12/21
 * Time: 19:42
 */

namespace app\store\controller;

use app\common\bean\GlobalBean;
use app\common\bean\ListMap;
use app\common\bean\StoreBean;
use app\common\bean\StoreCashBean;
use app\common\controller\StoreController;
use app\common\enum\StoreCashStatusEnum;
use app\common\manage\StoreCashManage;
use app\common\manage\StoreManage;
use app\common\utils\ExitJsonUtil;

class StoreCash extends StoreController
{
    public function add(){//申请提现

        if(request()->post()){
            $storeCashBean = new StoreCashBean();
            $storeCashBean->setData($this->postParams);
            $id = StoreCashManage::getInstance()->cash($storeCashBean);
            ExitJsonUtil::getInstance()->exitData($id);
        }else{
            $storeBean = new StoreBean();
            $storeBean->setId(session(GlobalBean::$storeId));
            $storeBean = StoreManage::getInstance()->getInfo($storeBean);
            $this->assign([
                'store'=>$storeBean->getData()
            ]);
            return $this->fetch();
        }
    }
    /**
     * 商家提现订单
     * @throws \Exception
     */
    public function storeCashList(){
        $listMap = new ListMap();
        $listMap->setData($this->getParams);
        $listMap->setParameter(StoreCashBean::$storeId,session(GlobalBean::$storeId));
        $storeCashMap = StoreCashManage::getInstance()->getPaginatorList($listMap);
        $this->assign("storeCashList",$storeCashMap->getList());
        $this->assign("currentPage",$storeCashMap->getCurrentPage());
        $this->assign("totalCount",$storeCashMap->getTotalCount());
        $this->assign('statusSelect',StoreCashStatusEnum::getArrayName());
        return $this->fetch();
    }

    /**
     * 审核提现订单
     * @throws \Exception
     */
    public function reviewStoreCash(){
        $storeCashBean = new StoreCashBean();
        $storeCashBean->setData($this->getParams);
        $storeCashBean = StoreCashManage::getInstance()->getInfo($storeCashBean);
        $statusSelect = StoreCashStatusEnum::getArrayName();
        $this->assign('storeCash',$storeCashBean->getData());
        $this->assign('statusSelect',$statusSelect);
        return $this->fetch();
    }
}